package cn.test.controller;

import cn.summit.captcha.service.CaptchaCodeCreator;
import cn.test.dto.CaptchaDTO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.UUID;

/**
 * @author summit
 * @since 2020/12/1 16:40
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/captcha")
@Slf4j
public class CaptchaController {

    private final CaptchaCodeCreator captchaCodeCreator;

    @GetMapping
    public void test(HttpServletResponse response) throws IOException {
        String responseImage = captchaCodeCreator.getResponseImage(response.getOutputStream());
        log.debug("验证码 {}", responseImage);
    }

    @GetMapping("/base64")
    public CaptchaDTO getCaptchaDTO() {
        CaptchaDTO dto = new CaptchaDTO();
        dto.setCaptchaId(UUID.randomUUID().toString().replace("-", ""));
       // dto.setBase64Img(captchaCodeCreator.outputImage(););
        return dto;
    }
}
